package com.heima.controller.sku;

import com.heima.common.PageResult;
import com.heima.common.Result;
import com.heima.pojo.SkuClass;
import com.heima.pojo.dto.SkuClassPageDTO;
import com.heima.service.SkuClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/vm-service/skuClass")
public class SkuClassController {
    @Autowired
    private SkuClassService skuClassService;

    @GetMapping("/search")
    public PageResult searchVm(SkuClassPageDTO skuClassPageDTO){
        return skuClassService.pageQuery(skuClassPageDTO);
    }

    /**
     * 新增商品类型
     */
    @PostMapping
    public Result add(@RequestBody SkuClass skuClass){
        skuClassService.add(skuClass);
        return Result.success();
    }

    @DeleteMapping("/{classId}")
    public Result delete(@PathVariable Integer classId){
        skuClassService.delete(classId);
        return Result.success();
    }

    @PutMapping("/{classId}")
    public Result update(@PathVariable Integer classId, @RequestBody SkuClass skuClass){
        skuClassService.update(classId,skuClass);
        return Result.success();
    }

    @GetMapping("/{classId}")
    public Result queryById(@PathVariable Integer classId){
        return Result.success(skuClassService.queryById(classId));
    }

}
